#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-15 6:21 下午
# @Author  : yangdy
# @File    : 翻转字符串里的单词
# @Software: PyCharmCE


class Solution:
    def reverseWords(self, s: str) -> str:
        ans = ''
        s_list = s.split(' ')
        s_list.reverse()
        ans = ' '.join(list(filter(lambda x: x != '', s_list)))
        return ans


solve = Solution()

questions = [
    ("the sky is blue",),
    ("  hello world!  ",),
    ("a good   example",),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    print('ans:', solve.reverseWords(q[0]))

